package com.syq.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.syq.constants.ResultCode;
import lombok.Data;
import lombok.ToString;

/**
 * @author Sun Yueqi
 * @version 1.00
 * @time 2022/5/25 20:17
 */
@Data
@ToString
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class R {
    private int code;
    private String msg;
    private Object data;

    public static R setResult(int code,String msg,Object data){
        R r = new R();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static R setOk(){
        return setOk(null);
    }

    public static R setOk(Object data){
        return setResult(ResultCode.SUCCESS,"成功",data);
    }

    public static R setError(Object data){
        return setResult(ResultCode.ERROR,"失败",data);
    }

    public static R setError(){
        return setError(null);
    }
}
